package com.ikangtai.util;

import android.content.Context;
import android.telephony.TelephonyManager;

/**
 * Created by jerry on 15/12/9.
 * need add <uses-permission android:name="android.permission.READ_PHONE_STATE"/> in
 * AndroidManifest.xml
 */
public class DeviceInfo {
    private TelephonyManager tm;

    private StringBuilder sb = new StringBuilder();
    private String devicedIdIMEI;
    private String deviceSoftwareVersion;
    private String line1Number;
    private String networkCountryIso;
    private String networkOperator;
    private String networkOperatorName;
    private int networkType;
    private int phoneType;
    private String simCountryIso;
    private String simOperator;
    private String simOperatorName;
    private String simSerialNumber;
    private int simState;
    private String subscriberIdIMSI;
    private String soiceMailNumber;

    public DeviceInfo(Context context){
        tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    }

    public String getDevicedIdIMEI(){
        return (null == tm) ? null : tm.getDeviceId();
    }

    public String getDeviceSoftwareVersion(){
        return (null == tm) ? null : tm.getDeviceSoftwareVersion();
    }

    public String getLine1Number(){
        return (null == tm) ? null : tm.getLine1Number();
    }

    public String getNetworkCountryIso(){
        return (null == tm) ? null : tm.getNetworkCountryIso();
    }

    public String getNetworkOperator(){
        return (null == tm) ? null : tm.getNetworkOperator();
    }

    public String getNetworkOperatorName(){
        return (null == tm) ? null : tm.getNetworkOperatorName();
    }

    public int getNetworkType(){
        return (null == tm) ? null : tm.getNetworkType();
    }

    public int getPhoneType(){
        return (null == tm) ? null : tm.getPhoneType();
    }

    public String getSimCountryIso(){
        return (null == tm) ? null : tm.getSimCountryIso();
    }

    public String getSimOperator(){
        return (null == tm) ? null : tm.getSimOperator();
    }

    public String getSimOperatorName(){
        return (null == tm) ? null : tm.getSimOperatorName();
    }

    public String getSimSerialNumber(){
        return (null == tm) ? null : tm.getSimSerialNumber();
    }

    public int getSimState(){
        return (null == tm) ? null : tm.getSimState();
    }

    public String getSubscriberIdIMSI(){
        return (null == tm) ? null : tm.getSubscriberId();
    }

    public String getVoiceMailNumber(){
        return (null == tm) ? null : tm.getVoiceMailNumber();
    }

    public String getDeviceInfo(){
        if(null == tm)
            return null;
        else{
            sb.append("\nDeviceId(IMEI) = " + tm.getDeviceId());
            sb.append("\nDeviceSoftwareVersion = " + tm.getDeviceSoftwareVersion());
            sb.append("\nLine1Number = " + tm.getLine1Number());
            sb.append("\nNetworkCountryIso = " + tm.getNetworkCountryIso());
            sb.append("\nNetworkOperator = " + tm.getNetworkOperator());
            sb.append("\nNetworkOperatorName = " + tm.getNetworkOperatorName());
            sb.append("\nNetworkType = " + tm.getNetworkType());
            sb.append("\nPhoneType = " + tm.getPhoneType());
            sb.append("\nSimCountryIso = " + tm.getSimCountryIso());
            sb.append("\nSimOperator = " + tm.getSimOperator());
            sb.append("\nSimOperatorName = " + tm.getSimOperatorName());
            sb.append("\nSimSerialNumber = " + tm.getSimSerialNumber());
            sb.append("\nSimState = " + tm.getSimState());
            sb.append("\nSubscriberId(IMSI) = " + tm.getSubscriberId());
            sb.append("\nVoiceMailNumber = " + tm.getVoiceMailNumber());

            return sb.toString();
        }
    }

}
